<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <title>地图</title>
    <style>
        html, body, #container {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
        #container {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
        }
        #satellite-toggle {
            position: absolute;
            right: 20px;
            bottom: 100px;
            background: white;
            padding: 8px 12px;
            border-radius: 4px;
            box-shadow: 0 2px 6px rgba(0,0,0,0.3);
            cursor: pointer;
            z-index: 100;
        }
    </style>
</head>
<body>
    <div id="container"></div>
    <button id="satellite-toggle">切换卫星图</button>
    <script type="text/javascript">
        window._AMapSecurityConfig = {
            securityJsCode: '73461d6630069dc7405e7d1b6f4f0f37'
        }
    </script>
    <script type="text/javascript">
        let map;
        let satelliteLayer;
        let isSatelliteVisible = false;

        function initMap() {
            try {
                console.log('开始初始化地图...');
                // 从URL参数获取经纬度
                const urlParams = new URLSearchParams(window.location.search);
                const longitude = parseFloat(urlParams.get('longitude')) || 116.397428;
                const latitude = parseFloat(urlParams.get('latitude')) || 39.90923;

                console.log('经纬度:', longitude, latitude);

                // 创建地图实例
                map = new AMap.Map('container', {
                    zoom: 11,
                    center: [longitude, latitude],
                    viewMode: '2D',
                    pitch: 0
                });
                
                console.log('地图实例创建成功');

                // 创建卫星图层
                satelliteLayer = new AMap.TileLayer.Satellite({
                    zIndex: 1,
                });

                // 添加标记点
                var marker = new AMap.Marker({
                    position: [longitude, latitude],
                    map: map,
                    content:'xxx'
                });

                // 添加定位插件
                map.plugin(['AMap.Geolocation', 'AMap.Scale', 'AMap.ToolBar'], function() {
                    // 添加定位控件
                    map.addControl(new AMap.Geolocation({
                        position: 'RB',
                        offset: [10, 20]
                    }));
                    
                    // 添加比例尺
                    map.addControl(new AMap.Scale());
                    
                    // 添加工具条
                    map.addControl(new AMap.ToolBar({
                        position: 'RB'
                    }));
                });

                // 添加卫星图切换按钮事件监听
                document.getElementById('satellite-toggle').addEventListener('click', toggleSatellite);
                
                console.log('所有控件和标记点添加完成');
            } catch (error) {
                console.error('地图初始化错误:', error);
            }
        }

        function toggleSatellite() {
            if (!isSatelliteVisible) {
                map.add(satelliteLayer);
                isSatelliteVisible = true;
                document.getElementById('satellite-toggle').textContent = '关闭卫星图';
            } else {
                map.remove(satelliteLayer);
                isSatelliteVisible = false;
                document.getElementById('satellite-toggle').textContent = '切换卫星图';
            }
        }
    </script>
    <script src="https://webapi.amap.com/maps?v=2.0&key=d2196ac155452e3066a3406250f09e53&callback=initMap"></script>
</body>
</html> 